package com.dkm.biz.gl.repository.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.gl.domain.SmsHi;
import com.dkm.biz.gl.persistence.dao.SmsHiQueryDao;
import com.dkm.biz.gl.persistence.entity.SmsHiPo;
import com.dkm.biz.gl.repository.SmsHiRepository;
import com.dkm.biz.repository.AbstractRepository;

/**
 * 对象功能:t_gl_sms_hi Repository接口的实现类
 * 开发公司:HJ.COM
 * 开发人员:ZHH
 * 创建时间:2016-07-04 14:10:14
 */
@Repository
public class SmsHiRepositoryImpl extends AbstractRepository<String, SmsHiPo,SmsHi> implements SmsHiRepository{
	  
	@Resource
	private  SmsHiQueryDao smsHiQueryDao;

	public SmsHi newInstance() {
		SmsHiPo po = new SmsHiPo();
		SmsHi smsHi = SpringHelper.getBean(SmsHi.class);
		smsHi.setData(po);
		return smsHi;
	}

	public SmsHi newInstance(SmsHiPo po) {
		SmsHi smsHi = SpringHelper.getBean(SmsHi.class);
		smsHi.setData(po);
		return smsHi;
	} 
	
	@Override
	protected IQueryDao<String, SmsHiPo> getQueryDao() {
		return smsHiQueryDao;
	}

	@Override
	public List<SmsHiPo> findCodeByPhone(String phone, String smsCode) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("phone", phone);
		params.put("smsCode", smsCode);
		return smsHiQueryDao.findByKey("findCodeByPhone", params);
	}

	@Override
	public List<SmsHiPo> findCodeByPhone(String phone, String smsCode,String email,Integer registerType) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuffer sqlBuffer = new StringBuffer();
		if(registerType == 1){
			sqlBuffer.append("phone_="+phone);
		}else{
			sqlBuffer.append("email_="+email);
		}
		params.put("whereSql", sqlBuffer.toString());
		return smsHiQueryDao.findByKey("findCodeByPhone", params);
	}
	
}
